Delete Multiple User Issue

Greetings,
I have an issue deleting multiple users using a GUI.
I select the users from list and then use a function to delete all selected users.
using the deleteUser(u). In the routine I:
1. Make sure that the user exist (existsUser(u))
2. Load the Directory (loadDirectory())
3. Delete user (string err = deleteUser(u))
4. Check if user was deleted and does not exist (if(null err && !existsUser(u)))
5. saveDirectory
 

for(i = 0; i<noElems(lstUser);i++){
 if(selected(lstUser,i)){
 string uName = get(lstUser)
 User u = find(uName)
 if(existsUser(u)){
  loadDirectory()
  string error = deleteUser(u)
  saveDirectory()
  if((null error)&&(!existsUser(uName))){
     infoBox uName" has been deleted permanently."
  }
  else{
     ack "User not deleted: " error
  }
 }
}

 


The code above is an example of what i'm trying to do. In the second attempt it fails an return the ack message box, sometimes blank, sometimes with the error.

Am I doing something wrong?

 


SystemAdmin - Mon Oct 11 09:47:17 EDT 2010

Re: Delete Multiple User Issue
llandale - Thu Oct 14 16:11:49 EDT 2010

This part looks bad: if(selected(lstUser,i)){
string uName = get(lstUser)

Seems to me that if entry "i" is selected you want to get the user name associeated with entry "i", not the FIRST entry selected (get(1stUser)).
I'd be tempted to browse through all the selected elements of your multi-list, perhaps:

for UserName in lstUser do
{...

 


As for saving changes, I'm pretty sure you may need to 'load the user with one of the 1st 3 below, delete the user, then 'save' the user with the last one below:

 

 

string    loadUserRecord_(User,bool)
string  loadUserRecord(User)
string  ensureUserRecordLoaded(User)
 
string  saveUserRecord(User)


I've got similar code and finally made it work, but it fails when someone else is in the use directory at the same time. Hopefully, someone else will chime in here.

I'm guessing, but suppose that the 'existsUser' will return a false positive even if you actually deleted the user. string forceLoadDirectory() after you saveDirectory() may solve that. But loading/saving directories is slow, so I would routinely save that for the bottom of the function (do it once), THEN check to make sure the users are deleted.

When you get it working, Post the working code, this is tricky and others will need a good example.

 

 

 

  • Louie

 

 

Re: Delete Multiple User Issue
SystemAdmin - Thu Oct 14 16:57:02 EDT 2010

llandale - Thu Oct 14 16:11:49 EDT 2010

This part looks bad: if(selected(lstUser,i)){
string uName = get(lstUser)

Seems to me that if entry "i" is selected you want to get the user name associeated with entry "i", not the FIRST entry selected (get(1stUser)).
I'd be tempted to browse through all the selected elements of your multi-list, perhaps:

for UserName in lstUser do
{...

 


As for saving changes, I'm pretty sure you may need to 'load the user with one of the 1st 3 below, delete the user, then 'save' the user with the last one below:

 

 

string    loadUserRecord_(User,bool)
string  loadUserRecord(User)
string  ensureUserRecordLoaded(User)
 
string  saveUserRecord(User)


I've got similar code and finally made it work, but it fails when someone else is in the use directory at the same time. Hopefully, someone else will chime in here.

I'm guessing, but suppose that the 'existsUser' will return a false positive even if you actually deleted the user. string forceLoadDirectory() after you saveDirectory() may solve that. But loading/saving directories is slow, so I would routinely save that for the bottom of the function (do it once), THEN check to make sure the users are deleted.

When you get it working, Post the working code, this is tricky and others will need a good example.

 

 

 

  • Louie

 

 

This one helped just ok. I did not use the multiple selection, but all I need know is to be able to delete multiple users from using a single DB.
Follow this link for more information
Link:http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14542117
 

//Delete User Example                   
string lstArray [] = {}
DB userInfo
DBE lstUser, btnDeleteUser
 
User u
string uName
string mName = "/DOORS Admin/Users Log/Users Log"
//Module usersModule = edit(mName, false)
string dbName = getDatabaseName()
Skip uList
Skip inUsers
 
void getList (){
        int i = 0
        int j
        int pbNum = 0
        uList = createString()
        for u in userList do {
                uName = u.name
                put(uList, uName, uName)
        }
 
        deleteColumn(lstUser, 0)
        
        for uName in uList do{
                u = find(uName)
                bool isDisabled = u.disabled
                
                if(!isDisabled) {
                        insert(lstUser, i++, uName, iconUser)
                }     
                else{
                        insert(lstUser, i++, uName, iconUserDisabled)
                }
        }
 
        insertColumn(lstUser, 0, "Username", 150, iconNone)
}// End GetList Function (Actual User in Database)
 
void delUser(DBE Elem){
        
        {
                string uName = get(lstUser)
                string uGroups
                lastPos = get(lstUser)
                        
                User u = find(uName)
                uName = u.name
                if(existsUser(uName)){
                        if(confirm("Are you sure you want to delete '" uName "' ?")){
                                        if(confirm("Deleting an user is irreversible.\nAre you sure you want to delete '"uName"' ?")){
                                                /*current = usersModule
                                                Object o
                                                Filter f1 = attribute"Username"==uName
                                                set f1
                                                filtering on
                                                o = current
                                                if(!null o){
                                                        o."Active (T/F)" = "False"
                                                        o."Deletion Date" = today()
                
                                                        //Reason for Deletion Message Box
                                                        string options[] = {"Termination", "Inactivity"}
                                                        int ans = messageBox("Select Reason for Deletion", options, msgInfo)
                                                        o."Reason" = options[ans]
                                                        
                                                        Group g
                                                        Buffer temp = create(1)
                                                        for g in groupList do{
                                                                if(member(g, u)){
                                                                        uGroups = g.name
                                                                        temp += uGroups"\n"
                                                                }
                                                        }
                        
                                                        o."Groups" = temp""
                                                        save(usersModule)
                                                        refresh(usersModule)
                                                }
                                                else if(!confirm("User not found in log.\nDo you want to continue with deletion?")){       
                                                        return
                                                }*/
                                                loadDirectory()
                                                ensureUserRecordLoaded(u)
                                                string error = deleteUser(u)
                                                saveDirectory()
                                                empty(lstUser)
                                                getList()
                                                if((null error)&&(!existsUser(uName))){
                                                        infoBox uName" has been deleted permanently."
                                                }
                                                else{
                                                        ack "User not deleted: " error
                                                        /*o."Active (T/F)" = "True"
                                                        o."Deletion Date" = ""
                                                        o."Reason" = ""
                                                        save(usersModule)
                                                        refresh(usersModule)*/
                                                }
                                        } 
                                        else {
                                                ack"Abort Deletion"
                                                halt
                                        }
                        } 
                        else {
                                ack"Abort Deletion"
                                halt
                        }
                } 
                else {
                        infoBox"User Not found"
                }
        }
flushDeletions()
} // End Delete User
userInfo = create("Manage Users Tool - " dbName" v. 1.0", styleCentered|styleFixed)
lstUser = listView(userInfo, listViewOptionMultiselect|listViewOptionSortText, 625, 10, lstArray)
btnDeleteUser = button(userInfo, "Delete User", delUser)
realize(userInfo)
getList()
show(userInfo)

Re: Delete Multiple User Issue
SystemAdmin - Thu Oct 14 16:59:19 EDT 2010

SystemAdmin - Thu Oct 14 16:57:02 EDT 2010

This one helped just ok. I did not use the multiple selection, but all I need know is to be able to delete multiple users from using a single DB.
Follow this link for more information
Link:http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14542117
 

//Delete User Example                   
string lstArray [] = {}
DB userInfo
DBE lstUser, btnDeleteUser
 
User u
string uName
string mName = "/DOORS Admin/Users Log/Users Log"
//Module usersModule = edit(mName, false)
string dbName = getDatabaseName()
Skip uList
Skip inUsers
 
void getList (){
        int i = 0
        int j
        int pbNum = 0
        uList = createString()
        for u in userList do {
                uName = u.name
                put(uList, uName, uName)
        }
 
        deleteColumn(lstUser, 0)
        
        for uName in uList do{
                u = find(uName)
                bool isDisabled = u.disabled
                
                if(!isDisabled) {
                        insert(lstUser, i++, uName, iconUser)
                }     
                else{
                        insert(lstUser, i++, uName, iconUserDisabled)
                }
        }
 
        insertColumn(lstUser, 0, "Username", 150, iconNone)
}// End GetList Function (Actual User in Database)
 
void delUser(DBE Elem){
        
        {
                string uName = get(lstUser)
                string uGroups
                lastPos = get(lstUser)
                        
                User u = find(uName)
                uName = u.name
                if(existsUser(uName)){
                        if(confirm("Are you sure you want to delete '" uName "' ?")){
                                        if(confirm("Deleting an user is irreversible.\nAre you sure you want to delete '"uName"' ?")){
                                                /*current = usersModule
                                                Object o
                                                Filter f1 = attribute"Username"==uName
                                                set f1
                                                filtering on
                                                o = current
                                                if(!null o){
                                                        o."Active (T/F)" = "False"
                                                        o."Deletion Date" = today()
                
                                                        //Reason for Deletion Message Box
                                                        string options[] = {"Termination", "Inactivity"}
                                                        int ans = messageBox("Select Reason for Deletion", options, msgInfo)
                                                        o."Reason" = options[ans]
                                                        
                                                        Group g
                                                        Buffer temp = create(1)
                                                        for g in groupList do{
                                                                if(member(g, u)){
                                                                        uGroups = g.name
                                                                        temp += uGroups"\n"
                                                                }
                                                        }
                        
                                                        o."Groups" = temp""
                                                        save(usersModule)
                                                        refresh(usersModule)
                                                }
                                                else if(!confirm("User not found in log.\nDo you want to continue with deletion?")){       
                                                        return
                                                }*/
                                                loadDirectory()
                                                ensureUserRecordLoaded(u)
                                                string error = deleteUser(u)
                                                saveDirectory()
                                                empty(lstUser)
                                                getList()
                                                if((null error)&&(!existsUser(uName))){
                                                        infoBox uName" has been deleted permanently."
                                                }
                                                else{
                                                        ack "User not deleted: " error
                                                        /*o."Active (T/F)" = "True"
                                                        o."Deletion Date" = ""
                                                        o."Reason" = ""
                                                        save(usersModule)
                                                        refresh(usersModule)*/
                                                }
                                        } 
                                        else {
                                                ack"Abort Deletion"
                                                halt
                                        }
                        } 
                        else {
                                ack"Abort Deletion"
                                halt
                        }
                } 
                else {
                        infoBox"User Not found"
                }
        }
flushDeletions()
} // End Delete User
userInfo = create("Manage Users Tool - " dbName" v. 1.0", styleCentered|styleFixed)
lstUser = listView(userInfo, listViewOptionMultiselect|listViewOptionSortText, 625, 10, lstArray)
btnDeleteUser = button(userInfo, "Delete User", delUser)
realize(userInfo)
getList()
show(userInfo)

Remove the following from the code

loadDirectory()
flushDeletions()

 


Sorry.